<?php
if (!defined('BASEPATH'))
	exit('No direct script access allowed');
session_start();

class admin extends CI_Controller {
	function index() {
		//$this->load->view('view_adminupdate');
		$this -> load -> model('user_model');
		$this -> addnewsummary();
	}
	
	function addnewsummary(){
		$this -> load -> library('form_validation');
		$this -> form_validation -> set_rules('title', 'Title', 'required|max_length[55]');
		$this -> form_validation -> set_rules('summary', 'summary', 'required|max_length[55]');
		
		if ($this -> form_validation -> run() == FALSE) {
			//validation error
			$data['submiterror'] = (validation_errors());
			$this -> load -> view('view_adminupdate', $data);
		} else {
			//to database
			

			$this -> load -> model('admin_model');
			$title = $this -> input -> post('title');
			$summary = $this -> input -> post('summary');
			
			//$activation_code = $this -> _random_string(10);

			$this -> admin_model -> addnew($title, $summary);
			
			redirect('mainpage');
			
			//$data['success'] = "success";
			//$this -> load -> view('view_main', $data);
			
			}
		
	}
	
}
?>